<?php
	class MessageAction extends Action {
		protected $aVerify = array(
		   	'list_message',
		   	'add_reply',
		   	'del_mess',
		   	'del_reply',
		  	);//需要验证的方法
		public function list_message(){
			import('ORG.Util.Page');//导入分页类
			$cid = $_SESSION['company']['cid'];
			$count = D('message')->where(array('to'=>$cid,'is_del'=>0))->order('ctime DESC')->count();
			$Page = new Page($count,20);
        	$show = $Page ->show();
			$list = D('message')->where(array('to'=>$cid,'is_del'=>0))->order('ctime DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
			$cou =0;
			foreach($list as $k=>$v){
				$list[$k]['reply'] = D('message_reply')->where(array('mid'=>$list[$k]['mid'],'is_del'=>0))->select();
				if($list[$k]['reply'] == ""){
					$cou += 1;
				}
				
			}
			$this->assign('cou',$cou);	
			$this->assign('page',$show);
			$this->assign('list',$list);
			$menu = D('Company_menu')->select_menu();
			$this->assign('wei_note',$menu['wei_note']);
			$this->display();
		}
		public function add_reply(){
			if($this->_POST()){
				$map['cid'] = $_SESSION['company']['cid'];
				$map['mid'] = getRequest('mid');
				$map['content'] = getRequest('content');
				$map['ctime'] = time();
				$da = D('message_reply')->add($map);
				if($da){
					$this->success('提交成功','__URL__/list_message');
				}
			}
			
			
		}
		public function del_mess(){
			$mid = getRequest('mid');
			$ba = D('Message')->del_message($mid);
			if($ba){
				$this->ajaxReturn('','success',1);
			}else{
				$this->ajaxReturn('','error',0);
			}
		}
		public function del_reply(){
			$rid = getRequest('rid');
			$ba = D('message_reply')->where(array('rid'=>$rid))->save(array('is_del'=>1));
			if($ba){
				$this->ajaxReturn('','success',1);
			}else{
				$this->ajaxReturn('','error',0);
			}
		}
	}
?>